package com.geek.controller;

import com.geek.bean.BaseRespVo;
import com.geek.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("wx/user")
public class WxUserController {
    @Autowired
    UserService userService;
    @GetMapping("index")
    public BaseRespVo index(){
        //获取用户id
        Subject subject = SecurityUtils.getSubject();
        Integer userId = (Integer) subject.getPrincipal();
        if(subject.isAuthenticated()){
            //待评论uncomment
            Short uncomment = userService.getUncomment(userId);
            //待付款unpaid
            Integer unpaid = userService.getUnpaid(userId);

            //待收货unrecv
            Integer unrecv = userService.getUnrecv(userId);

            //待发货unship
            Integer unship = userService.getUnship(userId);

            Map<String, Integer> orderMap = new HashMap<>();
            orderMap.put("uncomment", Integer.valueOf(uncomment));
            orderMap.put("unpaid", unpaid);
            orderMap.put("unrecv", unrecv);
            orderMap.put("unship", unship);
            Map<String, Map<String, Integer>> dataMap = new HashMap<>();
            dataMap.put("order", orderMap);
            return BaseRespVo.ok(dataMap);
        }else {
            return BaseRespVo.unAuthc();
        }

    }
}
